Package("com.green.web.PersonDetail");
/* 费用类型 */
com.green.web.PersonDetail = {
	getAreaList : function(obj, name, level) {
		var ids = "";
		if (level == 3) {
			ids = $("#cityId").val();
			if (null == ids || ids == "") {
				art.dialog.alert("请选择城市！");
				$("#cityId").focus();
				return;
			}
		}
		if (level == 5) {
			ids = $("#areaId").val();
			if (null == ids || ids == "") {
				art.dialog.alert("请选择区域！");
				$("#areaId").focus();
				return;
			}
		}
		$('#areadiv').show();
		if (name == "city") {
			$('#areadiv .city-hd .current a').text("选择城市")
		} else if (name == "area") {
			$('#areadiv .city-hd .current a').text("选择区域")
		} else if (name == "plate") {
			$('#areadiv .city-hd .current a').text("选择板块")
		}
		;
		$('#areadiv').css({
			'top' : $(obj).offset().top + 23 + 'px',
			'left' : $(obj).offset().left + 'px'
		});
		var objNmae = obj.value;

		$
				.ajax({
					type : "POST",
					url : ctx + "/area/getArea",
					data : {
						"level" : level,
						"ids" : ids,
						"personId" : StringUtil.Url($("#personId").val()),
					},
					success : function(data) {
						var areaLists = data.areaList;
						var areaText = "";
						for ( var i = 0; i < areaLists.length; i++) {
							var area = areaLists[i];
							if (i == 0) {
								areaText = areaText
										+ "<li class=\"cityName\"><strong><label>"
										+ area.parent.name
										+ "</label></strong></li>";
							}
							var checkbox = "";
							if (objNmae.indexOf(area.name) >= 0) {
								checkbox = " checked='checked'";
							}
							areaText = areaText
									+ "<li class=\"\"><label> <input name=\"area\" id=\"area\" "
									+ checkbox
									+ "onclick=\"com.green.web.PersonDetail.onclickArea('"
									+ name
									+ "');\" type=\"checkbox\"  value=\""
									+ area.id + "\" />" + area.name
									+ "</label></li>";
							if (level != 2) {
								if (i < areaLists.length - 1) {
									var areas = areaLists[i + 1];
									if (areas.parent.id != area.parent.id)
										areaText = areaText
												+ "<li class=\"cityName\"><strong><label>"
												+ areas.parent.name
												+ "</label></strong></li>";
								}
							}
						}

						$("#areaList").html(areaText);
						com.green.web.PersonDetail.onclickArea(name);
					}
				});
	},
	onclickArea : function(name) {
		var areaId = "";
		var areaName = "";
		$(":checkbox:checked").each(function() {
			if (areaId != "") {
				areaId = areaId + "," + $(this).val();
				areaName = areaName + "," + $(this).parent().text();
			} else {
				areaId = $(this).val();
				areaName = $(this).parent().text();
			}
		});

		$("#" + name + "Name").val(areaName);
		$("#" + name + "Id").val(areaId);
	},
	addAreaPermission : function(level) {
		var ids = "";
		if (level == 2) {
			ids = $("#cityId").val();
			if (null == ids || ids == "") {
				art.dialog.alert("请选择城市！");
				$("#cityId").focus();
				return;
			}
		}
		if (level == 3) {
			ids = $("#areaId").val();
			if (null == ids || ids == "") {
				art.dialog.alert("请选择区域！");
				$("#areaId").focus();
				return;
			}
		}
		if (level == 5) {
			ids = $("#plateId").val();
			if (null == ids || ids == "") {
				art.dialog.alert("请选择板块！");
				$("#plateId").focus();
				return;
			}
		}
		$.ajax({
			type : "POST",
			url : ctx + "/person/saveAreaPermission",
			data : {
				"personId" : StringUtil.Url($("#personId").val()),
				"ids" : ids,
				"cityName" : $("#cityName").val()

			},
			success : function(data) {
				var ss = $.trim(data.message);
				if (ss == 1 || ss == "1") {
					art.dialog.optTips('您的操作已经成功', 2, "success");
					$('#areaUpdate').hide();

					$('#cityN').text($("#cityName").val());
					$('#areaN').text($("#areaName").val());
					if (level == 5) {
						$('#plateN').text($("#plateName").val());
					}
					art.dialog.close();
				} else {
					art.dialog.optTips('操作失败，请稍后再试', 2, "failure");
				}
			}
		});
	},
	selectOrg : function() {
		var longnumber = $("#longNumber").val();
		var dataName = $("#dataName").text();
		art.dialog.data("returnFunName", "selectOrg");
		art.dialog.data("dataName", dataName);
		art.dialog.open(ctx + '/f7/index/getOrg?flongnumber=s7~~' + longnumber,
				{
					title : '组织选择',
					lock : true,
					skin : 'aero',
					padding : 0,
					width : 450,
					height : 500
				});
	},
	deleteAreaPermission : function() {
		art.dialog.confirm("确认操作次功能？", function() {
			$.ajax({
				type : "POST",
				url : ctx + "/person/deleteAreaPermission",
				data : {
					"personId" : StringUtil.Url($("#personId").val())

				},
				success : function(data) {
					art.dialog.optTips('您的操作已经成功', 2, "success");
					$('#areaUpdate').hide();
					$('#cityN').text("");
					$('#areaN').text("");
					$('#plateN').text("");
					$("#cityName").val("");
					$("#areaName").val("");
					$("#plateName").val("");
				}
			});
		});
	},
	updateBranch : function() {
		$.ajax({
			type : "POST",
			url : ctx + "/person/updateBranch",
			data : {
				"personId" : StringUtil.Url($("#personId").val())

			},
			success : function(data) {
				art.dialog.optTips('您的操作已经成功', 2, "success");
			}
		});

	},
	deleteDataPermission : function() {
		art.dialog.confirm("确认操作次功能？", function() {
			$.ajax({
				type : "POST",
				url : ctx + "/person/deleteDataPermission",
				data : {
					"personId" : StringUtil.Url($("#personId").val())

				},
				success : function(data) {
					art.dialog.optTips('您的操作已经成功', 2, "success");
					$('#dataName').text("个人");
				}
			});
		});
	},
	isPlateUpdate : function(isPlate) {
		art.dialog.confirm("确认操作次功能？", function() {
			$.ajax({
				type : "POST",
				url : ctx + "/person/isPlateUpdate",
				data : {
					"personId" : StringUtil.Url($("#personId").val()),
					"isPlate":isPlate

				},
				success : function(data) {
					art.dialog.optTips('您的操作已经成功', 2, "success");
					location=ctx + '/person/openDetail?id='+StringUtil.Url($("#personId").val())
				}
			});
		});
	}
}